package com.wwwzh.himalayafm.adapter.live_adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.wwwzh.himalayafm.R;
import com.wwwzh.himalayafm.entity.entity_live.LocalRadios;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by wuruyuan on 2016/12/5.
 * 广播界面
 */

public class LocalAdapter extends RecyclerView.Adapter<LocalAdapter.ViewHolder>{
    private Context context;
    private List<LocalRadios> tops;

    public LocalAdapter(Context context) {
        this.context = context;
        tops=new ArrayList<>();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.live_iten_adapter, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.title.setText(tops.get(position).getName());
        holder.count.setText(tops.get(position).getPlayCount());
        loadImage(holder.image,tops.get(position).getCoverLarge());
    }
    private void loadImage(ImageView image, String coverLarge) {
        Picasso.with(image.getContext())
                .load(coverLarge)
                .into(image);
    }
    public void addAll(Collection<? extends LocalRadios> top) {
        int size=tops.size();
        tops.addAll(top);
        notifyItemRangeInserted(size,top.size());
    }

    @Override
    public int getItemCount() {
        return tops.size();
    }

    public static  class  ViewHolder extends RecyclerView.ViewHolder{
        private TextView title;
        private TextView count;
        private ImageView image;
        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.live_tv_title);
            count = (TextView) itemView.findViewById(R.id.live_tv_count);
            image = (ImageView) itemView.findViewById(R.id.live_image_hh);

        }
    }

}
